<template>
	<sw-search-tree-select v-model="checkedValue" :tree-data="departTreeData" :defaultProps="defaultProps" v-bind="$attrs" />
</template>

<script>
import lodash from 'lodash';
import { mapGetters } from 'vuex';
export default {
	name: 'swDepartSelect',
	props: {
		value: { type: String, default: '' },
		istop: { type: Boolean, default: false }
	},
	data() {
		return {
			checkedValue: this.value,
			defaultProps: { label: 'name', children: 'childList' }
		};
	},
	computed: {
		...mapGetters(['departTree']),
		departTreeData() {
			if (!this.istop) {
				return this.departTree;
			} else {
				let data = lodash.cloneDeep(this.departTree);
				return [{ id: '0', name: '顶级部门', childList: data }];
			}
		}
	},
	watch: {
		value(val) {
			this.checkedValue = val;
		},
		checkedValue(val) {
			this.$emit('input', val);
		}
	}
};
</script>

<style lang="scss" scoped></style>
